package site.shihuan.helpdesk.common.exception;

import org.apache.commons.lang3.StringUtils;
import site.shihuan.helpdesk.common.model.*;

/**
 * TODO
 *
 * @author 周世焕
 * @Date 2021/1/16 20:15
 */
public class CommonException extends RuntimeException{

    /**
     * serialVersionUID.
     */
    private static final long serialVersionUID = -3913902031489277776L;

    private int errCode;

    private String errMsg;

    public CommonException() {
    }

    public CommonException(IResultCode resultCode) {
        super(resultCode.getCodeMsg());
        this.errCode = resultCode.getCode();
        this.errMsg = resultCode.getCodeMsg();
    }

    public CommonException(final int errCode, final String errMsg) {
        super(errMsg);
        this.errCode = errCode;
        this.errMsg = errMsg;
    }

    public int getErrCode() {
        return this.errCode;
    }

    public String getErrMsg() {
        if (!StringUtils.isBlank(this.errMsg)) {
            return this.errMsg;
        }
        return Constants.NULL;
    }

    public void setErrCode(final int errCode) {
        this.errCode = errCode;
    }

    public void setErrMsg(final String errMsg) {
        this.errMsg = errMsg;
    }

    @Override
    public String toString() {
        return "ErrCode:" + getErrCode() + ", ErrMsg:" + getErrMsg();
    }
}
